package cn.anxingongyou.anxin.service.impl;

import cn.anxingongyou.anxin.entity.UserParent;
import cn.anxingongyou.anxin.mapper.UserParentMapper;
import cn.anxingongyou.anxin.service.UserParentService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class UserParentServiceImpl implements UserParentService {

    private final UserParentMapper userParentMapper;
    @Autowired
    public UserParentServiceImpl(UserParentMapper userParentMapper) {
        this.userParentMapper = userParentMapper;
    }

    @Override
    public int insert(UserParent userParent) {
        return userParentMapper.insertSelective(userParent);
    }

    @Override
    public int deleteByPrimaryKey(Long id) {
        return userParentMapper.deleteByPrimaryKey(id);
    }

    @Override
    public int updateByPrimaryKeySelective(UserParent userParent) {
        return userParentMapper.updateByPrimaryKeySelective(userParent);
    }

    @Override
    public UserParent selectOne(UserParent userParent) {
        return userParentMapper.selectOne(userParent);
    }

    @Override
    public UserParent selectOneByPrimaryKey(Long id) {
        return userParentMapper.selectByPrimaryKey(id);
    }

    @Override
    public PageInfo<UserParent> page(int pageNum, int pageSize, UserParent userParent) {
        String orderBy = "id desc";
        PageHelper pageHelper = new PageHelper();
        pageHelper.startPage(pageNum,pageSize,orderBy);
        List<UserParent> list = userParentMapper.select(userParent);
        PageInfo<UserParent> pageInfo = new PageInfo<>(list);
        return pageInfo;
    }
}
